package com.cnpinxi.controller.web.activity;

import com.cnpinxi.controller.base.BaseController;
import com.cnpinxi.domain.Activity;
import com.cnpinxi.myRunTime.MyRunTimeExcption;
import com.cnpinxi.result.ResultObj;
import com.cnpinxi.service.ActivityService;
import com.cnpinxi.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lutao on 2017/7/14.
 */
@RequestMapping("/activity")
@Controller
public class ActivityController extends BaseController {
    @Autowired
    ProductService productService;
    @Autowired
    ActivityService activityService;

    /**
     * 获取活动名称
     * @param activityId
     * @return
     */
    @RequestMapping(value = "/getActivity")
    @ResponseBody
    public String getActivity(Integer activityId){
        ResultObj resultObj = new ResultObj();
        resultObj.setCode(ResultObj.CODE_SUCCESS);
        try {
            if(activityId==null){
                throw new MyRunTimeExcption("产品不存在！");
            }
                Map<String,String> map=new HashMap<>();
                map.put("activityId",String.valueOf(activityId));
                Activity activity = activityService.getActivity(map);
                resultObj.setData(activity);
                resultObj.setMsg("操作成功！");
            resultObj.setCode(ResultObj.CODE_SUCCESS);

        } catch (MyRunTimeExcption myRunTimeExcption) {
            resultObj.setCode(ResultObj.CODE_FAIL);
            resultObj.setMsg(myRunTimeExcption.getMessage());
            myRunTimeExcption.printStackTrace();
        }catch (Exception e) {
            resultObj.setCode(ResultObj.CODE_FAIL);
            resultObj.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return resultObj.toJson();
    }
}
